#############################
# calculating Denmark ENPP  #
#############################

###library 

library(tidyverse)

### load data

den_seat<-read.csv("denmark_seatshre.csv")
attach(den_seat)
den_seat$perseat=absseat/totseats
den_seat<-na.omit(den_seat)


##calculate two types of ENPP

#molinar

tb_enpp_np<-
den_seat %>%group_by(date) %>%
  summarise(enpp_np=1+(1/(sum(perseat^2))*((sum(perseat^2)-max(perseat^2))/sum(perseat^2))))

#laakso
tb_enpp<-den_seat %>%group_by(date) %>%
  summarise(enpp=1/sum(perseat^2))

#combine two tibbles
enpp_denmark<-data.frame(tb_enpp_np,tb_enpp)

#output .csv
write.csv(enpp_denmark,"enpp_denmark.csv")
  
         

 
  
                               
                                 